<?php
class Store extends MY_Controller
{
	private $error = array(); 

	function index() {
		$this->lang->load('setting/store');
		$this->load->model('setting/Model_Config');
		$this->load->model('setting/Model_Store');
		
		//添加列表所需的js和css文档
		$this->document->setTitle($this->lang->line('heading_title'));
		$script = base_url()."includes/js/easyui/jquery.easyui.min.js";
		$this->document->addScript($script);
		
		$style_one = base_url()."includes/js/easyui/themes/default/easyui.css";
		$style_two = base_url()."includes/js/easyui/themes/icon.css";
		
		$this->document->addStyle($style_one);
		$this->document->addStyle($style_two);

		
		 
		

		$this->getList();
	}
	
	function datagrid()
	{
		$this->lang->load('setting/store');		
		$this->load->model('setting/Model_Store');
		$this->load->model('setting/Model_Config');
		
		
		
		if($this->input->post('page'))
		{
			$page = (int)$this->input->post('page');
			$rows = (int)$this->input->post('rows');
		}
		else
		{
			$page = 1;
			$rows = 10;
		}
		
		$array_one = array();
		
			$sort = $this->input->post('sort');
			
			switch($sort)
			{
				case "store_name":
				
					$sortone = "store.name ".$this->input->post('order');
					break;
				case "store_url":
					$sortone = "store.url ".$this->input->post('order');
					break;
				
				
				default:
					$sortone = "store.store_id ".$this->input->post('order');
					
			}
			
			
		$arrayone = array();
		
		$keyarray = array();	
		
			
		
		$offset = $rows*($page-1);
		$num = $rows;
		
		$array_one[] = array(
			'store_id' => 0,
			'name'     => $this->Model_Config->getKey('config_name') . $this->lang->line('text_default'),
			'url'      => HTTP_CATALOG,
			
		);
		
		$language_id = $this->Model_Config->getLanguageID($this->Model_Config->getKey('config_admin_language'));
		//$language_id = $this->Model_Config->getLanguageID('en');
		
		$dataone = $this->Model_Store->get_specific_all($rows, $offset, $sortone, $keyarray, $language_id);
		
		foreach($dataone->result() as $one)
		{
			
			$array_one[] = array(
				"store_id" => $one->store_id,
				"name" => $one->name,
				
				"url" => $one->url,
				
				
			);
			
			
		}
		
		$total_num = $this->Model_Store->get_specific_count_all($keyarray);
		
		
		$array = array(
			"total" => $total_num,
			"rows" => $array_one,
		);
		
		print_r(json_encode($array));
		
		
	
	}
	      
  	function insert() {
    	$this->lang->load('setting/store');

    	$this->document->setTitle($this->lang->line('heading_title')); 
		
		$this->load->model('setting/Model_Store');
		$this->load->model('setting/Model_Config');
		
    	if (($this->input->server('REQUEST_METHOD') == 'POST') && $this->validateForm()) {
			$store_id = $this->Model_Store->addStore($this->input->post());
	  		
			$this->load->model('setting/Model_Setting');
			
			$this->Model_Setting->editSetting('config', $this->input->post(), $store_id);
			
			if ($this->Model_Config->getKey('config_currency_auto') == 1) {
				$this->load->model('localisation/Model_Currency');
		
				$this->Model_Currency->updateCurrencies();
				
			}	
			
			$this->session->set_userdata['success'] = $this->lang->line('text_success');
			
			redirect(site_url().'/setting/store');
    	}
	
    	$this->getForm();
  	}

  	function update() {
    	$this->lang->load('setting/store');

    	$this->document->setTitle($this->lang->line('heading_title'));
		
		$this->load->model('setting/Model_Store');
		$this->load->model('setting/Model_Config');
	
    	if (($this->input->server('REQUEST_METHOD') == 'POST') && $this->validateForm()) {
			$this->Model_Store->editStore($this->uri->segment(4), $this->input->post());
			
			$this->load->model('setting/Model_Setting');
			
			$this->Model_Setting->editSetting('config', $this->input->post(), $this->uri->segment(4));
			
			if ($this->Model_Config->getKey('config_currency_auto')) {
				$this->load->model('localisation/Model_Currency');
		
				$this->Model_Currency->updateCurrencies();
				
				
				
			}	
			
			$this->session->set_userdata('success', $this->lang->line('text_success'));
			
			redirect(site_url().'/setting/store');
		}
		
    	$this->getForm();
  	}

  	
	
	function delete()
	{
		$success = false;
		$this->load->model('setting/Model_Store');
		$this->load->model('setting/Model_Setting');
		
		$store_ids = $this->input->post('store_ids');
		
		$cid = explode('-', $store_ids);
		
		if ($cid && $this->validateDelete()) {
			for($i=0; $i<count($cid); $i++)
			{
				$success = $this->Model_Store->deleteStore($cid[$i]);
				$this->Model_Setting->deleteSetting('config', $cid[$i]);
			}
			
			if($success)
			{
				echo "succ";
			}
			else
			{
				echo "fail1";
			}
		}
		else
		{
			echo "fail2";
		}
		
	}
	
	function getList() {
		
		
		
  		$data['breadcrumbs'] = array();

   		$data['breadcrumbs'][] = array(
       		'text'      => $this->lang->line('text_home'),
			'href'      => site_url().'/common/home',
      		'separator' => false
   		);

   		$data['breadcrumbs'][] = array(
       		'text'      => $this->lang->line('heading_title'),
			'href'      => site_url().'/setting/store',
      		'separator' => ' :: '
   		);
							
		$data['insert'] = site_url().'/setting/store/insert';
		$data['delete'] = site_url().'/setting/store/delete';	
		$data['edit'] = site_url().'/setting/store/update';
		
		$data['datagrid'] = site_url().'/setting/store/datagrid';

		$data['stores'] = array();
		
		
					
		
	
		$data['heading_title'] = $this->lang->line('heading_title');

		$data['text_no_results'] = $this->lang->line('text_no_results');

		$data['column_name'] = $this->lang->line('column_name');
		$data['column_url'] = $this->lang->line('column_url');
		$data['column_action'] = $this->lang->line('column_action');	
		
		$data['message_selections'] = $this->lang->line('message_selections');			
		
		$data['button_insert'] = $this->lang->line('button_insert');
		$data['button_delete'] = $this->lang->line('button_delete');
		$data['button_edit'] = $this->lang->line('button_edit');
 
 		if ($this->session->userdata('warning')) {
			$data['error_warning'] = $this->session->userdata('warning');
		} else {
			$data['error_warning'] = '';
		}
		
		
		
		
		if ($this->session->userdata('success')) {
			$data['success'] = $this->session->userdata('success');
			$this->session->unset_userdata('success');
		} else {
			$data['success'] = '';
		}

		$data['header'] = helper_load_header();
		$data['footer'] = helper_load_footer();
		
		$this->load->view('setting/store_list', $data);
	}
	 
	function getForm() { 
		$data['heading_title'] = $this->lang->line('heading_title');
		 
		$data['text_none'] = $this->lang->line('text_none');
		$data['text_yes'] = $this->lang->line('text_yes');
		$data['text_no'] = $this->lang->line('text_no');
		$data['text_image_manager'] = $this->lang->line('text_image_manager');
		$data['text_mail'] = $this->lang->line('text_mail');
		$data['text_smtp'] = $this->lang->line('text_smtp');
		
		$data['entry_name'] = $this->lang->line('entry_name');
		$data['entry_owner'] = $this->lang->line('entry_owner');
		$data['entry_address'] = $this->lang->line('entry_address');
		$data['entry_email'] = $this->lang->line('entry_email');
		$data['entry_telephone'] = $this->lang->line('entry_telephone');
		$data['entry_fax'] = $this->lang->line('entry_fax');		
		$data['entry_title'] = $this->lang->line('entry_title');
		$data['entry_meta_description'] = $this->lang->line('entry_meta_description');
		$data['entry_layout'] = $this->lang->line('entry_layout');
		$data['entry_template'] = $this->lang->line('entry_template');
		$data['entry_checkout_name'] = $this->lang->line('entry_checkout_name');
		$data['entry_checkout_logo'] = $this->lang->line('entry_checkout_logo');
		$data['entry_checkout_address'] = $this->lang->line('entry_checkout_address');
		$data['entry_checkout_email'] = $this->lang->line('entry_checkout_email');
		$data['entry_checkout_telephone'] = $this->lang->line('entry_checkout_telephone');
		$data['entry_checkout_fax'] = $this->lang->line('entry_checkout_fax');		
		$data['entry_country'] = $this->lang->line('entry_country');
		$data['entry_zone'] = $this->lang->line('entry_zone');		
		$data['entry_language'] = $this->lang->line('entry_language');
		$data['entry_language_id'] = $this->lang->line('entry_language_id');
		$data['entry_admin_language'] = $this->lang->line('entry_admin_language');
		$data['entry_currency'] = $this->lang->line('entry_currency');
		$data['entry_currency_auto'] = $this->lang->line('entry_currency_auto');
		$data['entry_length_class'] = $this->lang->line('entry_length_class');
		$data['entry_weight_class'] = $this->lang->line('entry_weight_class');
		$data['entry_catalog_limit'] = $this->lang->line('entry_catalog_limit');
		$data['entry_admin_limit'] = $this->lang->line('entry_admin_limit');
		$data['entry_tax'] = $this->lang->line('entry_tax');
		$data['entry_invoice_prefix'] = $this->lang->line('entry_invoice_prefix');
		$data['entry_customer_group'] = $this->lang->line('entry_customer_group');
		$data['entry_customer_price'] = $this->lang->line('entry_customer_price');
		$data['entry_customer_approval'] = $this->lang->line('entry_customer_approval');
		$data['entry_guest_checkout'] = $this->lang->line('entry_guest_checkout');
		$data['entry_account'] = $this->lang->line('entry_account');
		$data['entry_checkout'] = $this->lang->line('entry_checkout');
		$data['entry_affiliate'] = $this->lang->line('entry_affiliate');	
		$data['entry_commission'] = $this->lang->line('entry_commission');	
		$data['entry_stock_display'] = $this->lang->line('entry_stock_display');
		$data['entry_stock_warning'] = $this->lang->line('entry_stock_warning');
		$data['entry_stock_checkout'] = $this->lang->line('entry_stock_checkout');
		$data['entry_order_status'] = $this->lang->line('entry_order_status');
		$data['entry_complete_status'] = $this->lang->line('entry_complete_status');	
		$data['entry_return_status'] = $this->lang->line('entry_return_status');
		$data['entry_stock_status'] = $this->lang->line('entry_stock_status');
		$data['entry_review'] = $this->lang->line('entry_review');
		$data['entry_download'] = $this->lang->line('entry_download');
		$data['entry_upload_allowed'] = $this->lang->line('entry_upload_allowed');
		$data['entry_cart_weight'] = $this->lang->line('entry_cart_weight');
		$data['entry_logo'] = $this->lang->line('entry_logo');
		$data['entry_icon'] = $this->lang->line('entry_icon');
		$data['entry_image_thumb'] = $this->lang->line('entry_image_thumb');
		$data['entry_image_popup'] = $this->lang->line('entry_image_popup');
		$data['entry_image_product'] = $this->lang->line('entry_image_product');
		$data['entry_image_category'] = $this->lang->line('entry_image_category');
		$data['entry_image_manufacturer'] = $this->lang->line('entry_image_manufacturer');
		$data['entry_image_additional'] = $this->lang->line('entry_image_additional');
		$data['entry_image_related'] = $this->lang->line('entry_image_related');
		$data['entry_image_compare'] = $this->lang->line('entry_image_compare');
		$data['entry_image_wishlist'] = $this->lang->line('entry_image_wishlist');
		$data['entry_image_cart'] = $this->lang->line('entry_image_cart');		
		$data['entry_mail_protocol'] = $this->lang->line('entry_mail_protocol');
		$data['entry_mail_parameter'] = $this->lang->line('entry_mail_parameter');
		$data['entry_smtp_host'] = $this->lang->line('entry_smtp_host');
		$data['entry_smtp_username'] = $this->lang->line('entry_smtp_username');
		$data['entry_smtp_password'] = $this->lang->line('entry_smtp_password');
		$data['entry_smtp_port'] = $this->lang->line('entry_smtp_port');
		$data['entry_smtp_timeout'] = $this->lang->line('entry_smtp_timeout');
		$data['entry_alert_mail'] = $this->lang->line('entry_alert_mail');
		$data['entry_account_mail'] = $this->lang->line('entry_account_mail');
		$data['entry_alert_emails'] = $this->lang->line('entry_alert_emails');
		$data['entry_use_ssl'] = $this->lang->line('entry_use_ssl');
		$data['entry_maintenance'] = $this->lang->line('entry_maintenance');
		$data['entry_encryption'] = $this->lang->line('entry_encryption');
		$data['entry_seo_url'] = $this->lang->line('entry_seo_url');
		$data['entry_compression'] = $this->lang->line('entry_compression');
		$data['entry_error_display'] = $this->lang->line('entry_error_display');
		$data['entry_error_log'] = $this->lang->line('entry_error_log');
		$data['entry_error_filename'] = $this->lang->line('entry_error_filename');
		$data['entry_google_analytics'] = $this->lang->line('entry_google_analytics');
		
		$data['button_save'] = $this->lang->line('button_save');
		$data['button_cancel'] = $this->lang->line('button_cancel');

		$data['tab_general'] = $this->lang->line('tab_general');
		$data['tab_store'] = $this->lang->line('tab_store');
		$data['tab_checkout_template'] = $this->lang->line('tab_checkout_template');
		$data['tab_local'] = $this->lang->line('tab_local');
		$data['tab_option'] = $this->lang->line('tab_option');
		$data['tab_image'] = $this->lang->line('tab_image');
		$data['tab_mail'] = $this->lang->line('tab_mail');
		$data['tab_server'] = $this->lang->line('tab_server');
		
		
		
 		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}
		
 		if (isset($this->error['name'])) {
			$data['error_name'] = $this->error['name'];
		} else {
			$data['error_name'] = '';
		}
		
 		if (isset($this->error['owner'])) {
			$data['error_owner'] = $this->error['owner'];
		} else {
			$data['error_owner'] = '';
		}

 		if (isset($this->error['address'])) {
			$data['error_address'] = $this->error['address'];
		} else {
			$data['error_address'] = '';
		}
		
 		if (isset($this->error['email'])) {
			$data['error_email'] = $this->error['email'];
		} else {
			$data['error_email'] = '';
		}

		if (isset($this->error['telephone'])) {
			$data['error_telephone'] = $this->error['telephone'];
		} else {
			$data['error_telephone'] = '';
		}
 
  		if (isset($this->error['title'])) {
			$data['error_title'] = $this->error['title'];
		} else {
			$data['error_title'] = '';
		}
		
 		if (isset($this->error['image_thumb'])) {
			$data['error_image_thumb'] = $this->error['image_thumb'];
		} else {
			$data['error_image_thumb'] = '';
		}
		
 		if (isset($this->error['image_popup'])) {
			$data['error_image_popup'] = $this->error['image_popup'];
		} else {
			$data['error_image_popup'] = '';
		}
		
 		if (isset($this->error['image_product'])) {
			$data['error_image_product'] = $this->error['image_product'];
		} else {
			$data['error_image_product'] = '';
		}
				
 		if (isset($this->error['image_category'])) {
			$data['error_image_category'] = $this->error['image_category'];
		} else {
			$data['error_image_category'] = '';
		}
		
 		if (isset($this->error['image_manufacturer'])) {
			$data['error_image_manufacturer'] = $this->error['image_manufacturer'];
		} else {
			$data['error_image_manufacturer'] = '';
		}
		
 		if (isset($this->error['image_additional'])) {
			$data['error_image_additional'] = $this->error['image_additional'];
		} else {
			$data['error_image_additional'] = '';
		}	
		
 		if (isset($this->error['image_related'])) {
			$data['error_image_related'] = $this->error['image_related'];
		} else {
			$data['error_image_related'] = '';
		}
		
 		if (isset($this->error['image_compare'])) {
			$data['error_image_compare'] = $this->error['image_compare'];
		} else {
			$data['error_image_compare'] = '';
		}
		
  		if (isset($this->error['image_wishlist'])) {
			$data['error_image_wishlist'] = $this->error['image_wishlist'];
		} else {
			$data['error_image_wishlist'] = '';
		}
				
		if (isset($this->error['image_cart'])) {
			$data['error_image_cart'] = $this->error['image_cart'];
		} else {
			$data['error_image_cart'] = '';
		}
				
		if (isset($this->error['error_filename'])) {
			$data['error_error_filename'] = $this->error['error_filename'];
		} else {
			$data['error_error_filename'] = '';
		}		
		
		if (isset($this->error['catalog_limit'])) {
			$data['error_catalog_limit'] = $this->error['catalog_limit'];
		} else {
			$data['error_catalog_limit'] = '';
		}
		
		if (isset($this->error['admin_limit'])) {
			$data['error_admin_limit'] = $this->error['admin_limit'];
		} else {
			$data['error_admin_limit'] = '';
		}
		
  		$data['breadcrumbs'] = array();

   		$data['breadcrumbs'][] = array(
       		'text'      => $this->lang->line('text_home'),
			'href'      => site_url().'/common/home',
      		'separator' => false
   		);

   		$data['breadcrumbs'][] = array(
       		'text'      => $this->lang->line('heading_title'),
			'href'      => site_url().'/setting/store',
      		'separator' => ' :: '
   		);
		
		if (isset($this->session->userdata['success'])) {
			$data['success'] = $this->session->userdata['success'];
		
			unset($this->session->userdata['success']);
		} else {
			$data['success'] = '';
		}
		
		if ($this->uri->segment(4) === FALSE) {
			
			$data['action'] = site_url().'/setting/store/insert';
			
		} else {
			$data['action'] = site_url().'/setting/store/update/' . (int)$this->uri->segment(4);
		}
				
		$data['cancel'] = site_url().'/setting/store';
		
		//如果是编辑，则获取该store的相关数据
		if ($this->input->server('REQUEST_METHOD') != 'POST') {
			$this->load->model('setting/Model_Setting');
			
      		$store_info = $this->Model_Setting->getSetting('config', (int)$this->uri->segment(4));
    	}
		
		//print_r($store_info);
////////////////////////////////////////////////////////////////////////////////////////////////////////

		if ($this->input->post('config_name')) {
			$data['config_name'] = $this->input->post('config_name');
		} elseif (isset($store_info['config_name'])) {
			$data['config_name'] = $store_info['config_name'];
		} else {
			$data['config_name'] = '';
		}
	
		if ($this->input->post('config_owner')) {
			$data['config_owner'] = $this->input->post('config_owner');
		} elseif (isset($store_info['config_owner'])) {
			$data['config_owner'] = $store_info['config_owner'];		
		} else {
			$data['config_owner'] = '';
		}

		if ($this->input->post('config_address')) {
			$data['config_address'] = $this->input->post('config_address');
		} elseif (isset($store_info['config_address'])) {
			$data['config_address'] = $store_info['config_address'];		
		} else {
			$data['config_address'] = '';
		}
		
		if ($this->input->post('config_email')) {
			$data['config_email'] = $this->input->post('config_email');
		} elseif (isset($store_info['config_email'])) {
			$data['config_email'] = $store_info['config_email'];		
		} else {
			$data['config_email'] = '';
		}
		
		if ($this->input->post('config_telephone')) {
			$data['config_telephone'] = $this->input->post('config_telephone');
		} elseif (isset($store_info['config_telephone'])) {
			$data['config_telephone'] = $store_info['config_telephone'];		
		} else {
			$data['config_telephone'] = '';
		}

		if ($this->input->post('config_fax')) {
			$data['config_fax'] = $this->input->post('config_fax');
		} elseif (isset($store_info['config_fax'])) {
			$data['config_fax'] = $store_info['config_fax'];		
		} else {
			$data['config_fax'] = '';
		}

		if ($this->input->post('config_title')) {
			$data['config_title'] = $this->input->post('config_title');
		} elseif (isset($store_info['config_title'])) {
			$data['config_title'] = $store_info['config_title'];
		} else {
			$data['config_title'] = '';
		}
		
		if ($this->input->post('config_meta_description')) {
			$data['config_meta_description'] = $this->input->post('config_meta_description');
		} elseif (isset($store_info['config_meta_description'])) {
			$data['config_meta_description'] = $store_info['config_meta_description'];		
		} else {
			$data['config_meta_description'] = '';
		}

		
		if ($this->input->post('config_layout_id')) {
			$data['config_layout_id'] = $this->input->post('config_layout_id');
		} elseif (isset($store_info['config_layout_id'])) {
			$data['config_layout_id'] = $store_info['config_layout_id'];
		} else {
			$data['config_layout_id'] = '';
		}
				
		$this->load->model('design/Model_Layout');
		
		$data['layouts'] = $this->Model_Layout->getLayouts();
				
		if ($this->input->post('config_template')) {
			$data['config_template'] = $this->input->post('config_template');
		} elseif (isset($store_info['config_template'])) {
			$data['config_template'] = $store_info['config_template'];
		} else {
			$data['config_template'] = '';
		}

		
		
		//获取模板
		$data['templates'] = array();

		$directories = glob(DIR_CATALOG . 'theme/*', GLOB_ONLYDIR);
		
		foreach ($directories as $directory) {
			$data['templates'][] = basename($directory);
		}	
//////////////////////////////////////////////////////////////////////////////////////////////////////////								
		
		$this->load->model('tool/Model_Image');

		if ($this->input->post('config_checkout_name')) {
			$data['config_checkout_name'] = $this->input->post('config_checkout_name');
		} elseif (isset($store_info['config_checkout_name'])) {
			$data['config_checkout_name'] = $store_info['config_checkout_name'];
		} else {
			$data['config_checkout_name'] = '';
		}

		if ($this->input->post('config_checkout_logo')) {
			$data['config_checkout_logo'] = $this->input->post('config_checkout_logo');
		} elseif (isset($store_info['config_checkout_logo'])) {
			$data['config_checkout_logo'] = $store_info['config_checkout_logo'];			
		} else {
			$data['config_checkout_logo'] = '';
		}

		if (isset($store_info['config_checkout_logo']) && file_exists(DIR_IMAGE . $store_info['config_checkout_logo']) && is_file(DIR_IMAGE . $store_info['config_checkout_logo'])) {
			$data['checkout_logo'] = $this->Model_Image->resize($store_info['config_checkout_logo'], 100, 100);		
		} else {
			$data['checkout_logo'] = $this->Model_Image->resize('no_image.jpg', 100, 100);
		}

		if ($this->input->post('config_checkout_address')) {
			$data['config_checkout_address'] = $this->input->post('config_checkout_address');
		} elseif (isset($store_info['config_checkout_address'])) {
			$data['config_checkout_address'] = $store_info['config_checkout_address'];		
		} else {
			$data['config_checkout_address'] = '';
		}
		
		if ($this->input->post('config_checkout_email')) {
			$data['config_checkout_email'] = $this->input->post('config_checkout_email');
		} elseif (isset($store_info['config_checkout_email'])) {
			$data['config_checkout_email'] = $store_info['config_checkout_email'];		
		} else {
			$data['config_checkout_email'] = '';
		}
		
		if ($this->input->post('config_checkout_telephone')) {
			$data['config_checkout_telephone'] = $this->input->post('config_checkout_telephone');
		} elseif (isset($store_info['config_checkout_telephone'])) {
			$data['config_checkout_telephone'] = $store_info['config_checkout_telephone'];		
		} else {
			$data['config_checkout_telephone'] = '';
		}

		if ($this->input->post('config_checkout_fax')) {
			$data['config_checkout_fax'] = $this->input->post('config_checkout_fax');
		} elseif (isset($store_info['config_checkout_fax'])) {
			$data['config_checkout_fax'] = $store_info['config_checkout_fax'];		
		} else {
			$data['config_checkout_fax'] = '';
		}
//////////////////////////////////////////////////////////////////////////////////////////////////////////								
		
		if ($this->input->post('config_country_id')) {
			$data['config_country_id'] = $this->input->post('config_country_id');
		} elseif (isset($store_info['config_country_id'])) {
			$data['config_country_id'] = $store_info['config_country_id'];		
		} else {
			
			$data['config_country_id'] = $this->Model_Config->getKey('config_country_id');
		}
		
		$this->load->model('localisation/Model_Country');
		
		$data['countries'] = $this->Model_Country->getCountries();

		if ($this->input->post('config_zone_id')) {
			$data['config_zone_id'] = $this->input->post('config_zone_id');
		} elseif (isset($store_info['config_zone_id'])) {
			$data['config_zone_id'] = $store_info['config_zone_id'];				
		} else {
			$data['config_zone_id'] = $this->Model_Config->getKey('config_zone_id');
		}	
		
		
		
		if ($this->input->post('config_language')) {
			$data['config_language'] = $this->input->post('config_language');
		} elseif (isset($store_info['config_language'])) {
			$data['config_language'] = $store_info['config_language'];			
		} else {
			$data['config_language'] = $this->Model_Config->getKey('config_language');
		}
		
		if ($this->input->post('config_language_id')) {
			$data['config_language_id'] = $this->input->post('config_language_id');
		} elseif (isset($store_info['config_language_id'])) {
			$data['config_language_id'] = $store_info['config_language_id'];			
		} else {
			$data['config_language_id'] = $this->Model_Config->getKey('config_language_id');
		}
		
		$this->load->model('localisation/Model_Language');
		
		$data['languages'] = $this->Model_Language->getLanguages();

				
		if ($this->input->post('config_admin_language')) {
			$data['config_admin_language'] = $this->input->post('config_admin_language');
		} else {
			$data['config_admin_language'] = $this->Model_Config->getKey('config_admin_language');
		}
		
		if ($this->input->post('config_currency')) {
			$data['config_currency'] = $this->input->post('config_currency');
		} elseif (isset($store_info['config_currency'])) {
			$data['config_currency'] = $store_info['config_currency'];			
		} else {
			$data['config_currency'] = $this->Model_Config->getKey('config_currency');
		}

		if ($this->input->post('config_currency_auto')) {
			$data['config_currency_auto'] = $this->input->post('config_currency_auto');
		} else {
			$data['config_currency_auto'] = $this->Model_Config->getKey('config_currency_auto');
		}
		
		$this->load->model('localisation/Model_Currency');
		
		$data['currencies'] = $this->Model_Currency->getCurrencies();

		if ($this->input->post('config_length_class')) {
			$data['config_length_class'] = $this->input->post('config_length_class');
		} else {
			$data['config_length_class'] = $this->Model_Config->getKey('config_length_class');
		}
		
		$this->load->model('localisation/Model_Length_Class');
		
		$data['length_classes'] = $this->Model_Length_Class->getLengthClasses();
		
		if ($this->input->post('config_weight_class')) {
			$data['config_weight_class'] = $this->input->post('config_weight_class');
		} else {
			$data['config_weight_class'] = $this->Model_Config->getKey('config_weight_class');
		}
		
		$this->load->model('localisation/Model_Weight_Class');
		
		$data['weight_classes'] = $this->Model_Weight_Class->getWeightClasses();
		
		if ($this->input->post('config_catalog_limit')) {
			$data['config_catalog_limit'] = $this->input->post('config_catalog_limit');
		} elseif (isset($store_info['config_catalog_limit'])) {
			$data['config_catalog_limit'] = $store_info['config_catalog_limit'];	
		} else {
			$data['config_catalog_limit'] = '12';
		}			
						
		if ($this->input->post('config_admin_limit')) {
			$data['config_admin_limit'] = $this->input->post('config_admin_limit');
		} else {
			$data['config_admin_limit'] = $this->Model_Config->getKey('config_admin_limit');
		}
		
		if ($this->input->post('config_tax')) {
			$data['config_tax'] = $this->input->post('config_tax');
		} elseif (isset($store_info['config_tax'])) {
			$data['config_tax'] = $store_info['config_tax'];			
		} else {
			$data['config_tax'] = '';
		}
		
		if ($this->input->post('config_invoice_prefix')) {
			$data['config_invoice_prefix'] = $this->input->post('config_invoice_prefix');
		} elseif ($this->Model_Config->getKey('config_invoice_prefix')) {
			$data['config_invoice_prefix'] = $this->Model_Config->getKey('config_invoice_prefix');			
		} else {
			$data['config_invoice_prefix'] = 'INV-' . date('Y') . '-00';
		}
		
		$this->load->model('sale/Model_Customer_Group');
		
		$data['customer_groups'] = $this->Model_Customer_Group->getCustomerGroups();
		
		if ($this->input->post('config_customer_group_id')) {
			$data['config_customer_group_id'] = $this->input->post('config_customer_group_id');
		} elseif (isset($store_info['config_customer_group_id'])) {
			$data['config_customer_group_id'] = $store_info['config_customer_group_id'];			
		} else {
			$data['config_customer_group_id'] = '';
		}
		
		if ($this->input->post('config_customer_price')) {
			$data['config_customer_price'] = $this->input->post('config_customer_price');
		} elseif (isset($store_info['config_customer_price'])) {
			$data['config_customer_price'] = $store_info['config_customer_price'];			
		} else {
			$data['config_customer_price'] = '';
		}
		
		if ($this->input->post('config_customer_approval')) {
			$data['config_customer_approval'] = $this->input->post('config_customer_approval');
		} elseif (isset($store_info['config_customer_approval'])) {
			$data['config_customer_approval'] = $store_info['config_customer_approval'];			
		} else {
			$data['config_customer_approval'] = '';
		}
		
		if ($this->input->post('config_guest_checkout')) {
			$data['config_guest_checkout'] = $this->input->post('config_guest_checkout');
		} elseif (isset($store_info['config_guest_checkout'])) {
			$data['config_guest_checkout'] = $store_info['config_guest_checkout'];		
		} else {
			$data['config_guest_checkout'] = '';
		}
		
		if ($this->input->post('config_account_id')) {
			$data['config_account_id'] = $this->input->post('config_account_id');
		} elseif (isset($store_info['config_account_id'])) {
			$data['config_account_id'] = $store_info['config_account_id'];			
		} else {
			$data['config_account_id'] = '';
		}
		
		if ($this->input->post('config_checkout_id')) {
			$data['config_checkout_id'] = $this->input->post('config_checkout_id');
		} elseif (isset($store_info['config_checkout_id'])) {
			$data['config_checkout_id'] = $store_info['config_checkout_id'];		
		} else {
			$data['config_checkout_id'] = '';
		}

		if ($this->input->post('config_affiliate_id')) {
			$data['config_affiliate_id'] = $this->input->post('config_affiliate_id');
		} else {
			$data['config_affiliate_id'] = $this->Model_Config->getKey('config_affiliate_id');		
		}
		
		if ($this->input->post('config_commission')) {
			$data['config_commission'] = $this->input->post('config_commission');
		} elseif ($this->Model_Config->getKey('config_commission')) {
			$data['config_commission'] = $this->Model_Config->getKey('config_commission');		
		} else {
			$data['config_commission'] = '5.00';
		}
		
		$this->load->model('catalog/Model_Information');
		
		$data['informations'] = $this->Model_Information->getInformations();
		
		if ($this->input->post('config_stock_display')) {
			$data['config_stock_display'] = $this->input->post('config_stock_display');
		} elseif (isset($store_info['config_stock_display'])) {
			$data['config_stock_display'] = $store_info['config_stock_display'];			
		} else {
			$data['config_stock_display'] = '';
		}
		
		if ($this->input->post('config_stock_warning')) {
			$data['config_stock_warning'] = $this->input->post('config_stock_warning');
		} else {
			$data['config_stock_warning'] = $this->Model_Config->getKey('config_stock_warning');		
		}

		if ($this->input->post('config_stock_checkout')) {
			$data['config_stock_checkout'] = $this->input->post('config_stock_checkout');
		} elseif (isset($store_info['config_stock_checkout'])) {
			$data['config_stock_checkout'] = $store_info['config_stock_checkout'];		
		} else {
			$data['config_stock_checkout'] = '';
		}
		
		if ($this->input->post('config_stock_status_id')) {
			$data['config_stock_status_id'] = $this->input->post('config_stock_status_id');
		} else {
			$data['config_stock_status_id'] = $this->Model_Config->getKey('config_stock_status_id');			
		}
		
		$this->load->model('localisation/Model_Stock_Status');
		
		$data['stock_statuses'] = $this->Model_Stock_Status->getStockStatuses();
		
		if ($this->input->post('config_order_status_id')) {
			$data['config_order_status_id'] = $this->input->post('config_order_status_id');
		} elseif (isset($store_info['config_order_status_id'])) {
			$data['config_order_status_id'] = $store_info['config_order_status_id'];		
		} else {
			$data['config_order_status_id'] = '';
		}
		
		$this->load->model('localisation/Model_Order_Status');
		
		$data['order_statuses'] = $this->Model_Order_Status->getOrderStatuses();
		
		if ($this->input->post('config_complete_status_id')) {
			$data['config_complete_status_id'] = $this->input->post('config_complete_status_id');
		} else {
			$data['config_complete_status_id'] = $this->Model_Config->getKey('config_complete_status_id');
		}
				
		if ($this->input->post('config_return_status_id')) {
			$data['config_return_status_id'] = $this->input->post('config_return_status_id');
		} else {
			$data['config_return_status_id'] = $this->Model_Config->getKey('config_return_status_id');		
		}
		
		$this->load->model('localisation/Model_Return_Status');
		
		$data['return_statuses'] = $this->Model_Return_Status->getReturnStatuses();	
				
		if ($this->input->post('config_review_status')) {
			$data['config_review_status'] = $this->input->post('config_review_status');
		} else {
			$data['config_review_status'] = $this->Model_Config->getKey('config_review_status');
		}
		
		if ($this->input->post('config_download')) {
			$data['config_download'] = $this->input->post('config_download');
		} else {
			$data['config_download'] = $this->Model_Config->getKey('config_download');
		}

		if ($this->input->post('config_upload_allowed')) {
			$data['config_upload_allowed'] = $this->input->post('config_upload_allowed');
		} else {
			$data['config_upload_allowed'] = $this->Model_Config->getKey('config_upload_allowed');
		}
				
		if ($this->input->post('config_cart_weight')) {
			$data['config_cart_weight'] = $this->input->post('config_cart_weight');
		} elseif (isset($store_info['config_cart_weight'])) {
			$data['config_cart_weight'] = $store_info['config_cart_weight'];	
		} else {
			$data['config_cart_weight'] = '';
		}

		if ($this->input->post('config_logo')) {
			$data['config_logo'] = $this->input->post('config_logo');
		} elseif (isset($store_info['config_logo'])) {
			$data['config_logo'] = $store_info['config_logo'];			
		} else {
			$data['config_logo'] = '';
		}

		if (isset($store_info['config_logo']) && file_exists(DIR_IMAGE . $store_info['config_logo']) && is_file(DIR_IMAGE . $store_info['config_logo'])) {
			$data['logo'] = $this->Model_Image->resize($store_info['config_logo'], 100, 100);		
		} else {
			$data['logo'] = $this->Model_Image->resize('no_image.jpg', 100, 100);
		}

		if ($this->input->post('config_icon')) {
			$data['config_icon'] = $this->input->post('config_icon');
		} elseif (isset($store_info['config_icon'])) {
			$data['config_icon'] = $store_info['config_icon'];			
		} else {
			$data['config_icon'] = '';
		}
		
		if (isset($store_info['config_icon']) && file_exists(DIR_IMAGE . $store_info['config_icon']) && is_file(DIR_IMAGE . $store_info['config_icon'])) {
			$data['icon'] = $this->Model_Image->resize($store_info['config_icon'], 100, 100);
		} else {
			$data['icon'] = $this->Model_Image->resize('no_image.jpg', 100, 100);
		}
		
		if ($this->input->post('config_image_thumb_width')) {
			$data['config_image_thumb_width'] = $this->input->post('config_image_thumb_width');
		} elseif (isset($store_info['config_image_thumb_width'])) {
			$data['config_image_thumb_width'] = $store_info['config_image_thumb_width'];			
		} else {
			$data['config_image_thumb_width'] = 228;
		}
		
		if ($this->input->post('config_image_thumb_height')) {
			$data['config_image_thumb_height'] = $this->input->post('config_image_thumb_height');
		} elseif (isset($store_info['config_image_thumb_height'])) {
			$data['config_image_thumb_height'] = $store_info['config_image_thumb_height'];				
		} else {
			$data['config_image_thumb_height'] = 228;
		}
		
		if ($this->input->post('config_image_popup_width')) {
			$data['config_image_popup_width'] = $this->input->post('config_image_popup_width');
		} elseif (isset($store_info['config_image_popup_width'])) {
			$data['config_image_popup_width'] = $store_info['config_image_popup_width'];			
		} else {
			$data['config_image_popup_width'] = 500;
		}
		
		if ($this->input->post('config_image_popup_height')) {
			$data['config_image_popup_height'] = $this->input->post('config_image_popup_height');
		} elseif (isset($store_info['config_image_popup_height'])) {
			$data['config_image_popup_height'] = $store_info['config_image_popup_height'];			
		} else {
			$data['config_image_popup_height'] = 500;
		}
		
		if ($this->input->post('config_image_product_width')) {
			$data['config_image_product_width'] = $this->input->post('config_image_product_width');
		} elseif (isset($store_info['config_image_product_width'])) {
			$data['config_image_product_width'] = $store_info['config_image_product_width'];		
		} else {
			$data['config_image_product_width'] = 80;
		}
		
		if ($this->input->post('config_image_product_height')) {
			$data['config_image_product_height'] = $this->input->post('config_image_product_height');
		} elseif (isset($store_info['config_image_product_height'])) {
			$data['config_image_product_height'] = $store_info['config_image_product_height'];		
		} else {
			$data['config_image_product_height'] = 80;
		}
		
		if ($this->input->post('config_image_category_width')) {
			$data['config_image_category_width'] = $this->input->post('config_image_category_width');
		} elseif (isset($store_info['config_image_category_width'])) {
			$data['config_image_category_width'] = $store_info['config_image_category_width'];			
		} else {
			$data['config_image_category_width'] = 80;
		}
						
		if ($this->input->post('config_image_category_height')) {
			$data['config_image_category_height'] = $this->input->post('config_image_category_height');
		} elseif (isset($store_info['config_image_category_height'])) {
			$data['config_image_category_height'] = $store_info['config_image_category_height'];			
		} else {
			$data['config_image_category_height'] = 80;
		}	
				
		if ($this->input->post('config_image_manufacturer_width')) {
			$data['config_image_manufacturer_width'] = $this->input->post('config_image_manufacturer_width');
		} elseif (isset($store_info['config_image_manufacturer_width'])) {
			$data['config_image_manufacturer_width'] = $store_info['config_image_manufacturer_width'];			
		} else {
			$data['config_image_manufacturer_width'] = 80;
		}
						
		if ($this->input->post('config_image_manufacturer_height')) {
			$data['config_image_manufacturer_height'] = $this->input->post('config_image_manufacturer_height');
		} elseif (isset($store_info['config_image_manufacturer_height'])) {
			$data['config_image_manufacturer_height'] = $store_info['config_image_manufacturer_height'];			
		} else {
			$data['config_image_manufacturer_height'] = 80;
		}
		
		if ($this->input->post('config_image_additional_width')) {
			$data['config_image_additional_width'] = $this->input->post('config_image_additional_width');
		} elseif (isset($store_info['config_image_additional_width'])) {
			$data['config_image_additional_width'] = $store_info['config_image_additional_width'];			
		} else {
			$data['config_image_additional_width'] = 74;
		}
		
		if ($this->input->post('config_image_additional_height')) {
			$data['config_image_additional_height'] = $this->input->post('config_image_additional_height');
		} elseif (isset($store_info['config_image_additional_height'])) {
			$data['config_image_additional_height'] = $store_info['config_image_additional_height'];				
		} else {
			$data['config_image_additional_height'] = 74;
		}
		
		if ($this->input->post('config_image_related_width')) {
			$data['config_image_related_width'] = $this->input->post('config_image_related_width');
		} elseif (isset($store_info['config_image_related_width'])) {
			$data['config_image_related_width'] = $store_info['config_image_related_width'];		
		} else {
			$data['config_image_related_width'] = 80;
		}
		
		if ($this->input->post('config_image_related_height')) {
			$data['config_image_related_height'] = $this->input->post('config_image_related_height');
		} elseif (isset($store_info['config_image_related_height'])) {
			$data['config_image_related_height'] = $store_info['config_image_related_height'];			
		} else {
			$data['config_image_related_height'] = 80;
		}
		
		if ($this->input->post('config_image_compare_width')) {
			$data['config_image_compare_width'] = $this->input->post('config_image_compare_width');
		} elseif (isset($store_info['config_image_compare_width'])) {
			$data['config_image_compare_width'] = $store_info['config_image_compare_width'];			
		} else {
			$data['config_image_compare_width'] = 90;
		}
		
		if ($this->input->post('config_image_compare_height')) {
			$data['config_image_compare_height'] = $this->input->post('config_image_compare_height');
		} elseif (isset($store_info['config_image_compare_height'])) {
			$data['config_image_compare_height'] = $store_info['config_image_compare_height'];			
		} else {
			$data['config_image_compare_height'] = 90;
		}
		
		if ($this->input->post('config_image_wishlist_width')) {
			$data['config_image_wishlist_width'] = $this->input->post('config_image_wishlist_width');
		} elseif (isset($store_info['config_image_wishlist_width'])) {
			$data['config_image_wishlist_width'] = $store_info['config_image_wishlist_width'];			
		} else {
			$data['config_image_wishlist_width'] = 50;
		}
		
		if ($this->input->post('config_image_wishlist_height')) {
			$data['config_image_wishlist_height'] = $this->input->post('config_image_wishlist_height');
		} elseif (isset($store_info['config_image_wishlist_height'])) {
			$data['config_image_wishlist_height'] = $store_info['config_image_wishlist_height'];			
		} else {
			$data['config_image_wishlist_height'] = 50;
		}
				
		if ($this->input->post('config_image_cart_width')) {
			$data['config_image_cart_width'] = $this->input->post('config_image_cart_width');
		} elseif (isset($store_info['config_image_cart_width'])) {
			$data['config_image_cart_width'] = $store_info['config_image_cart_width'];			
		} else {
			$data['config_image_cart_width'] = 80;
		}
		
		if ($this->input->post('config_image_cart_height')) {
			$data['config_image_cart_height'] = $this->input->post('config_image_cart_height');
		} elseif (isset($store_info['config_image_cart_height'])) {
			$data['config_image_cart_height'] = $store_info['config_image_cart_height'];			
		} else {
			$data['config_image_cart_height'] = 80;
		}
		
		if ($this->input->post('config_mail_protocol')) {
			$data['config_mail_protocol'] = $this->input->post('config_mail_protocol');
		} else {
			$data['config_mail_protocol'] = $this->Model_Config->getKey('config_mail_protocol');
		}
		
		if ($this->input->post('config_mail_parameter')) {
			$data['config_mail_parameter'] = $this->input->post('config_mail_parameter');
		} else {
			$data['config_mail_parameter'] = $this->Model_Config->getKey('config_mail_parameter');
		}
				
		if ($this->input->post('config_smtp_host')) {
			$data['config_smtp_host'] = $this->input->post('config_smtp_host');
		} else {
			$data['config_smtp_host'] = $this->Model_Config->getKey('config_smtp_host');
		}		

		if ($this->input->post('config_smtp_username')) {
			$data['config_smtp_username'] = $this->input->post('config_smtp_username');
		} else {
			$data['config_smtp_username'] = $this->Model_Config->getKey('config_smtp_username');
		}	
		
		if ($this->input->post('config_smtp_password')) {
			$data['config_smtp_password'] = $this->input->post('config_smtp_password');
		} else {
			$data['config_smtp_password'] = $this->Model_Config->getKey('config_smtp_password');
		}	
		
		if ($this->input->post('config_smtp_port')) {
			$data['config_smtp_port'] = $this->input->post('config_smtp_port');
		} elseif ($this->Model_Config->getKey('config_smtp_port')) {
			$data['config_smtp_port'] = $this->Model_Config->getKey('config_smtp_port');
		} else {
			$data['config_smtp_port'] = 25;
		}	
		
		if ($this->input->post('config_smtp_timeout')) {
			$data['config_smtp_timeout'] = $this->input->post('config_smtp_timeout');
		} elseif ($this->Model_Config->getKey('config_smtp_timeout')) {
			$data['config_smtp_timeout'] = $this->Model_Config->getKey('config_smtp_timeout');
		} else {
			$data['config_smtp_timeout'] = 5;	
		}	
		
		if ($this->input->post('config_alert_mail')) {
			$data['config_alert_mail'] = $this->input->post('config_alert_mail');
		} else {
			$data['config_alert_mail'] = $this->Model_Config->getKey('config_alert_mail');
		}

		if ($this->input->post('config_account_mail')) {
			$data['config_account_mail'] = $this->input->post('config_account_mail');
		} else {
			$data['config_account_mail'] = $this->Model_Config->getKey('config_account_mail');
		}
		
		if ($this->input->post('config_alert_emails')) {
			$data['config_alert_emails'] = $this->input->post('config_alert_emails');
		} else {
			$data['config_alert_emails'] = $this->Model_Config->getKey('config_alert_emails');
		}

		if ($this->input->post('config_use_ssl')) {
			$data['config_use_ssl'] = $this->input->post('config_use_ssl');
		} elseif (isset($store_info['config_use_ssl'])) {
			$data['config_use_ssl'] = $store_info['config_use_ssl'];
		} else {
			$data['config_use_ssl'] = '';
		}
		
		if ($this->input->post('config_seo_url')) {
			$data['config_seo_url'] = $this->input->post('config_seo_url');
		} else {
			$data['config_seo_url'] = $this->Model_Config->getKey('config_seo_url');
		}
		
		if ($this->input->post('config_maintenance')) {
			$data['config_maintenance'] = $this->input->post('config_maintenance');
		} else {
			$data['config_maintenance'] = $this->Model_Config->getKey('config_maintenance');
		}
		
		if ($this->input->post('config_encryption')) {
			$data['config_encryption'] = $this->input->post('config_encryption');
		} else {
			$data['config_encryption'] = $this->Model_Config->getKey('config_encryption');
		}
		
		if ($this->input->post('config_compression')) {
			$data['config_compression'] = $this->input->post('config_compression'); 
		} else {
			$data['config_compression'] = $this->Model_Config->getKey('config_compression');
		}

		if ($this->input->post('config_error_display')) {
			$data['config_error_display'] = $this->input->post('config_error_display'); 
		} else {
			$data['config_error_display'] = $this->Model_Config->getKey('config_error_display');
		}

		if ($this->input->post('config_error_log')) {
			$data['config_error_log'] = $this->input->post('config_error_log'); 
		} else {
			$data['config_error_log'] = $this->Model_Config->getKey('config_error_log');
		}

		if ($this->input->post('config_error_filename')) {
			$data['config_error_filename'] = $this->input->post('config_error_filename'); 
		} else {
			$data['config_error_filename'] = $this->Model_Config->getKey('config_error_filename');
		}
				
		if ($this->input->post('config_google_analytics')) {
			$data['config_google_analytics'] = $this->input->post('config_google_analytics'); 
		} else {
			$data['config_google_analytics'] = $this->Model_Config->getKey('config_google_analytics');
		}
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////		
		
		

		

		$data['header'] = helper_load_header();
		$data['footer'] = helper_load_footer();
						
		$this->load->view('setting/store_form', $data);
	}

	private function validateForm() {
		if (!$this->Model_User->has_permission('store_edit', $this->session->userdata('user_id'))) {
			$this->error['warning'] = $this->lang->line('error_permission');
		}
		
		if (!$this->input->post('config_name')) {
			$this->error['name'] = $this->lang->line('error_name');
		}	
		
		if ((strlen(utf8_decode($this->input->post('config_owner'))) < 3) || (strlen(utf8_decode($this->input->post('config_owner'))) > 64)) {
			$this->error['owner'] = $this->lang->line('error_owner');
		}

		if ((strlen(utf8_decode($this->input->post('config_address'))) < 3) || (strlen(utf8_decode($this->input->post('config_address'))) > 256)) {
			$this->error['address'] = $this->lang->line('error_address');
		}
		
    	if ((strlen(utf8_decode($this->input->post('config_email'))) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->input->post('config_email'))) {
      		$this->error['email'] = $this->lang->line('error_email');
    	}

    	if ((strlen(utf8_decode($this->input->post('config_telephone'))) < 3) || (strlen(utf8_decode($this->input->post('config_telephone'))) > 32)) {
      		$this->error['telephone'] = $this->lang->line('error_telephone');
    	}

		if (!$this->input->post('config_title')) {
			$this->error['title'] = $this->lang->line('error_title');
		}	
		
		if (!$this->input->post('config_image_thumb_width') || !$this->input->post('config_image_thumb_height')) {
			$this->error['image_thumb'] = $this->lang->line('error_image_thumb');
		}	
		
		if (!$this->input->post('config_image_popup_width') || !$this->input->post('config_image_popup_height')) {
			$this->error['image_popup'] = $this->lang->line('error_image_popup');
		}	
		
		if (!$this->input->post('config_image_product_width') || !$this->input->post('config_image_product_height')) {
			$this->error['image_product'] = $this->lang->line('error_image_product');
		}
				
		if (!$this->input->post('config_image_category_width') || !$this->input->post('config_image_category_height')) {
			$this->error['image_category'] = $this->lang->line('error_image_category');
		} 
		
		if (!$this->input->post('config_image_manufacturer_width') || !$this->input->post('config_image_manufacturer_height')) {
			$this->error['image_manufacturer'] = $this->lang->line('error_image_manufacturer');
		} 
				
		if (!$this->input->post('config_image_additional_width') || !$this->input->post('config_image_additional_height')) {
			$this->error['image_additional'] = $this->lang->line('error_image_additional');
		}
		
		if (!$this->input->post('config_image_related_width') || !$this->input->post('config_image_related_height')) {
			$this->error['image_related'] = $this->lang->line('error_image_related');
		}
		
		if (!$this->input->post('config_image_compare_width') || !$this->input->post('config_image_compare_height')) {
			$this->error['image_compare'] = $this->lang->line('error_image_compare');
		}
		
		if (!$this->input->post('config_image_wishlist_width') || !$this->input->post('config_image_wishlist_height')) {
			$this->error['image_wishlist'] = $this->lang->line('error_image_wishlist');
		}			
		
		if (!$this->input->post('config_image_cart_width') || !$this->input->post('config_image_cart_height')) {
			$this->error['image_cart'] = $this->lang->line('error_image_cart');
		}
		
		if (!$this->input->post('config_error_filename')) {
			$this->error['error_filename'] = $this->lang->line('error_error_filename');
		}
		
		if (!$this->input->post('config_admin_limit')) {
			$this->error['admin_limit'] = $this->lang->line('error_limit');
		}
		
		if (!$this->input->post('config_catalog_limit')) {
			$this->error['catalog_limit'] = $this->lang->line('error_limit');
		}
		
		if ($this->error && !isset($this->error['warning'])) {
			$this->error['warning'] = $this->lang->line('error_warning');
		}
		
		
		//如果有错误，但不是警告信息，则将警告信息赋值
		if ($this->error && !isset($this->error['warning'])) {
			$this->error['warning'] = $this->lang->line('error_warning');
		}
					
		if (!$this->error) {
			return true;
		} else {
			return false;
		}
	}

	private function validateDelete() {
		if (!$this->Model_User->has_permission('store_delete', $this->session->userdata('user_id'))) {
			$this->error['warning'] = $this->lang->line('error_permission');
		}
		
		$this->load->model('sale/Model_Order');
		
		$store_ids = $this->input->post('store_ids');
		
		$mid = explode('-', $store_ids);
		
		for($i = 0; $i < count($mid); $i++)
		{
			$store_total = $this->Model_Order->getTotalOrdersByStoreId($mid[$i]);
			if ($store_total) {
	  			$this->error['warning'] = sprintf($this->lang->line('error_store'), $store_total);
			}
		}
		
		
		
		if (!$this->error) {
			return true; 
		} else {
			return false;
		}
	}
	
	function template() {
		$template = basename($this->uri->segment(4));
		
		if (file_exists(DIR_IMAGE . 'templates/' . $template . '.png')) {
			$image = HTTP_IMAGE . 'templates/' . $template . '.png';
		} else {
			$image = HTTP_IMAGE . 'no_image.jpg';
		}
		
		echo '<img src="' . $image . '" alt="" title="" style="border: 1px solid #EEEEEE;" />';
	}		
	
	function zone() {
		$output = '';
		
		$this->load->model('localisation/Model_Zone');
		
		$results = $this->Model_Zone->getZonesByCountryId($this->uri->segment(4));
		
		foreach ($results as $result) {
			$output .= '<option value="' . $result['zone_id'] . '"';

			if (((int)$this->uri->segment(5) != 0) && ($this->uri->segment(5) == $result['zone_id'])) {
				$output .= ' selected="selected"';
			}

			$output .= '>' . $result['name'] . '</option>';
		}

		if (!$results) {
			$output .= '<option value="0">' . $this->lang->line('text_none') . '</option>';
		}

		echo $output;
	}		
}
?>